package com.fulu.netty.luban.forthdemo;

import io.netty.channel.*;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import io.netty.util.concurrent.EventExecutorGroup;

public class HeartBeatHandler extends ChannelHandlerAdapter {
    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        if(evt instanceof IdleStateEvent){
            IdleStateEvent event = (IdleStateEvent) evt;
            if(event.state() == IdleState.READER_IDLE){
                System.out.println("读操作进入空闲");
            }else if(event.state() == IdleState.WRITER_IDLE){
                System.out.println("写操作进入空闲");
            }else if(event.state() == IdleState.ALL_IDLE){
                System.out.println("channel关闭前用户数" + ChatHandler.users.size());
                Channel channel = ctx.channel();
                channel.close();
                System.out.println("channel关闭后用户数" + ChatHandler.users.size());
            }
        }
    }
}
